import React from 'react';
import {inject, observer} from 'mobx-react';
import { withRouter } from 'react-router-dom';
import { Form , RouteLayout , ListEditable } from 'weaver-mobile-page';
import { Icon, Result , Tools , Modal , Bubble,DatePicker,List,Button} from 'weaver-mobile';
import { toJS } from 'mobx';
import MeetingUtil from '../../../util/meetingUtil';
const ButtonGroup = RouteLayout.ButtonGroup;
const getLabel = Tools.getLabel;
const alert = Modal.alert;

@inject('viewMeetingStore')
@withRouter
@observer
class OverMeetingSet extends React.Component {
  constructor(props) {
      super(props);
      // this.state = {
      //   disabled:false,
      // };
    }

    componentWillMount(){
      //this.setState({disabled:false})
      // if(this.props.location.pathname === '/calendar/detail/decisionData'){
      //   const { setState } = this.props.viewMeetingStore;
      //   setState({isView:'1',renderToDecision:false})
      // }
    }
    
    componentDidMount() {
      //const { getSignCreateSet , setState ,meetingId} = this.props.viewMeetingStore;
      //考虑到刷新的时候
      //let meetingIdTemp = meetingId?meetingId:sessionStorage.getItem('meetingId')
      //getSignCreateSet();
    }

    componentWillReceiveProps (nextProps) {
      // if(nextProps.location.pathname === '/calendar/detail/decisionData'){
      //   const { setState } = this.props.viewMeetingStore;
      //   setState({isView:'1'})
      // }
    }

    componentWillUnmount () {
      
    }

    //这里改造一下，传start和end，只取这其外的字段。
  range = (start, end) => {
    const result = [];
    for (let i = start; i < end; i++) {
      result.push(i);
    }
    return result;
  }

  rangeH = (start, end) => {
    const result = [];
    for (let i = 0; i < start; i++) {
      result.push(i);
    }
    for (let j = end; j < 24; j++) {
      result.push(j);
    }
    return result;
  }

  rangeM = (start, end) => {
    const result = [];
    for (let i = 0; i < start; i++) {
      result.push(i);
    }
    for (let j = end; j < 60; j++) {
      result.push(j);
    }
    return result;
  }

  getHeight = () => {
    return document.body.clientHeight - MeetingUtil.getTabHeight() - MeetingUtil.getButtonHeight();
  }

  getBtns = ()=>{
    let { meetingEndDate ,meetingBeginDate,nowValue } = this.props.viewMeetingStore;
    let viewMeetingStore = this.props.viewMeetingStore;
    let baseBtns = [];
    let meetingid = viewMeetingStore.meetingid;
    baseBtns=[
      {
        key: 'add',
        type:'primary',
        text: getLabel(126003, '提前结束'),
        onClick: () => {viewMeetingStore.overMeeting({'meetingid':meetingid,'overTime':nowValue},this.goBack)},
      }
    ]
    return baseBtns;
  }
    dateFormat =(fmt, date)=> {
      let ret;
      const opt = {
          "Y+": date.getFullYear().toString(),        // 年
          "m+": (date.getMonth() + 1).toString(),     // 月
          "d+": date.getDate().toString(),            // 日
          "H+": date.getHours().toString(),           // 时
          "M+": date.getMinutes().toString(),         // 分
          "S+": date.getSeconds().toString()          // 秒
          // 有其他格式化字符需求可以继续添加，必须转化成字符串
      };
      for (let k in opt) {
          ret = new RegExp("(" + k + ")").exec(fmt);
          if (ret) {
              fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
          };
      };
      return fmt;
  }

  goBack = ()=>{
    this.props.history.goBack()
  }

    render() {
      let { meetingEndDate ,meetingBeginDate,nowValue ,setState} = this.props.viewMeetingStore;
      const { isView,type} = this.props.viewMeetingStore;
      const decisionHeight = this.getHeight();
      let baseBtns = this.getBtns();
      let viewMeetingStore = this.props.viewMeetingStore;
      let meetingid = viewMeetingStore.meetingid;
      return (
        <div style={{height:'100%'}}>
        <div className={'signcreate-data-contain'} >
        <DatePicker
          mode="datetime"
          value={nowValue}
          minDate={meetingBeginDate}
          maxDate={meetingEndDate}
          viewAttr={3}
          onChange={date => {
             setState({ nowValue: date })}
          } 
        >
          <List.Item arrow="horizontal">{getLabel('522575','会议结束日期时间')}</List.Item>
        </DatePicker>
        </div>
        <div className={'decision-button'}>
        <Button
          className={'decision-button'}
          type={'primary'}
          style={{'width':'100%','position':'absolute','bottom':'0px'}}
          onClick={() =>
          alert(getLabel('126004','确定要提前结束会议吗？'), '', [
            { text: getLabel(201,'取消'), onPress: () => console.log(nowValue) },
            { text: getLabel(826,'确定'), onPress: () => {viewMeetingStore.overMeeting({'meetingid':meetingid,'overTime':nowValue},this.goBack)} },
            ])
          }
        >
      {getLabel(126003, '提前结束')}
    </Button></div>
        </div>
      )
    }
}

export default OverMeetingSet;